home *** CD-ROM | disk | FTP | other *** search
/ Nebula 2 / Nebula Two.iso / SourceCode / Palettes / Chart / Source / PieChartInspector.m < prev    next >
Text File  |  1995-06-12  |  4KB  |  127 lines

  1. // -------------------------------------------------------------------------------------
  2. // PieChartInspector.m
  3. // Martin D. Flynn, NeXT Computer, Inc.
  4. // -------------------------------------------------------------------------------------
  5.  
  6. #import <appkit/appkit.h>
  7. #import <math.h>
  8. #import "PieChartInspector.h"
  9. #import "PieChart.h"
  10.  
  11. // -------------------------------------------------------------------------------------
  12. // nib mode methods
  13. @interface PieChart(Nib)
  14. - _initDefaultPie:(int)count;
  15. @end
  16.  
  17. // -------------------------------------------------------------------------------------
  18. @implementation PieChartInspector
  19.  
  20. // -------------------------------------------------------------------------------------
  21. // This method exists for linker purposes only.  It is not executed. 
  22. + forcePieChartLink { return [PieChart class]; }
  23.  
  24. // -------------------------------------------------------------------------------------
  25.  
  26. - init
  27. {
  28.     NXRect    r;
  29.     char    buff[MAXPATHLEN + 1];
  30.     id        pie, bundle;
  31.   
  32.     [super init];
  33.     bundle = [NXBundle bundleForClass:[self class]];
  34.     [bundle getPath:buff forResource:"PieChartInspector" ofType:"nib"];
  35.     [NXApp loadNibFile:buff owner:self withNames:NO fromZone:[self zone]];
  36.   
  37.     [colorPie getFrame:&r];
  38.     pie = [[PieChart alloc] initFrame:&r];
  39.     [colorPie setContentView:pie];
  40.     [pie setDrawLabels:NO];
  41.     [pie setDefaultSliceCount:0];
  42.     [pie setAcceptColor:YES];
  43.     [pie setDelegate:self];
  44.     colorPie = pie;
  45.   
  46.     return self;
  47. }
  48.  
  49. - revert:sender
  50. {
  51.   int    i, cnt = [object defaultSliceCount];
  52.   
  53.   /* options */
  54.   [[optionsMatrix findCellWithTag:0] setState:[object showPercent]];
  55.   [[optionsMatrix findCellWithTag:1] setState:[object drawSliceOutline]];
  56.   
  57.   /* colors */
  58.   [colorPie setBackgroundColor:[object backgroundColor]];
  59.   [colorPie setDefaultSliceCount:cnt];
  60.   [useDefaultGray setState:((cnt>0)?NO:YES)];
  61.   [maxSliceSlider setIntValue:cnt];
  62.   [maxSliceCount setIntValue:cnt];
  63.   [colorPie _initDefaultPie:cnt];
  64.   for (i = 0; i < cnt; i++) [colorPie setSliceColor:[object sliceColorAt:i] at:i];
  65.  
  66.   /* redisplay and return */
  67.   [window display];
  68.   return [super revert:sender];
  69. }
  70.  
  71. - ok:sender
  72. {
  73.   int    i;
  74.  
  75.   /* options */
  76.   [object setShowPercent:[[optionsMatrix findCellWithTag:0] state]];
  77.   [object setDrawSliceOutline:[[optionsMatrix findCellWithTag:1] state]];
  78.   
  79.   /* set slice colors */
  80.   [object setBackgroundColor:[colorPie backgroundColor]];
  81.   if ([useDefaultGray state]) [object setDefaultSliceCount:0];
  82.   else {
  83.     [object setDefaultSliceCount:[colorPie defaultSliceCount]];
  84.     for (i = 0; i < [colorPie defaultSliceCount]; i++)
  85.       [object setSliceColor:[colorPie sliceColorAt:i] at:i];
  86.   }
  87.   [object _initDefaultPie:-1];
  88.   
  89.   return [super ok:sender];
  90. }
  91.  
  92. - (BOOL)wantsButtons
  93. {
  94.     return YES;
  95. }
  96.  
  97. // -------------------------------------------------------------------------------------
  98.  
  99. - changeUseDefaultGray:sender
  100. {
  101.   [colorPie setDefaultSliceCount:([sender state]? 0 : [maxSliceSlider intValue])];
  102.   [colorPie _initDefaultPie:([sender state]? [maxSliceSlider intValue] : -1)];
  103.   return [colorPie display];
  104. }
  105.  
  106. - changeSliceCount:sender
  107. {
  108.   [maxSliceCount setIntValue:[sender intValue]];
  109.   if (![useDefaultGray state]) [colorPie setDefaultSliceCount:[sender intValue]];
  110.   [colorPie _initDefaultPie:[sender intValue]];
  111.   return [colorPie display];
  112. }
  113.  
  114. // -------------------------------------------------------------------------------------
  115.  
  116. /* PieChart delegate: pie slice selected */
  117. - selectedPieSlice:(int)n
  118. {
  119.   NXEvent    *e = [NXApp currentEvent];
  120.   NXColor    color = (n >= 0)? [colorPie sliceColorAt:n] : [colorPie backgroundColor];
  121.   if (e->data.mouse.click == 2) [sliceColorWell setColor:color];
  122.   else [NXColorPanel dragColor:color withEvent:e fromView:colorPie];
  123.   return self;
  124. }
  125.  
  126. @end
  127.